﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Meqs.Entity;
using Meqs.Logic.Interface;
using System.Collections.Generic;

public partial class Credit_Teacher_ScoreInput_Left : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void SetNavigate()
    {
        List<StuCasueHistoryView> list = (List<StuCasueHistoryView>)GetEvalList();
        int firestId = -1;
        if (list != null && list.Count > 0)
        {
            string str = "";
            Response.Write("if(document.getElementById('dd') != null)");
            Response.Write("{");
            Response.Write("    var dd = document.getElementById('dd');");
            int index = 0;
            if (SchoolCommon.CheckRole((int)RoleKeyEnum.Class_Teacher))
            {
                str += "<li class=\"active\"><a href=\"#\" id=\"0\" evaltype= \"1\" attribute=\"3\" onclick=\"leftNav(this, 0)\">&nbsp;&nbsp;&nbsp;&nbsp;各科学分评价录入</a></li>";
                index++;
            }

            if (SchoolCommon.CheckRole((int)RoleKeyEnum.Teach_Director))
            {
                foreach (StuCasueHistoryView item in list)
                {
                    if (item.EvalType == 4) continue;
                    if (firestId == -1)
                        firestId = item.RID;

                    if (index > 0)
                        str += "<li class=\"\"><a href=\"#\" id=\"" + item.RID + "\" onclick=\"leftNav(this, " + index + ")\" evaltype=\"" + item.EvalType + "\" attribute=\"" + item.Attribute + "\" status=\"" + item.Status + "\">&nbsp;&nbsp;&nbsp;&nbsp;" + item.Caption + "</a></li>";
                    else
                        str += "<li class=\"active\"><a href=\"#\" id=\"" + item.RID + "\" onclick=\"leftNav(this, " + index + ")\" evaltype=\"" + item.EvalType + "\"  attribute=\"" + item.Attribute + "\" status=\"" + item.Status + "\">&nbsp;&nbsp;&nbsp;&nbsp;" + item.Caption + "</a></li>";

                    index++;
                }
            }

            if (SchoolCommon.CheckRole((int)RoleKeyEnum.Class_Header))
            {
                foreach (StuCasueHistoryView item in list)
                {
                    
                    if (item.EvalType != 4) continue;
                    if (firestId == -1)
                        firestId = item.RID;
                    str += "<li><a href=\"#\" id=\"" + item.RID + "\" onclick=\"leftNav(this, " + index + ")\" evaltype=\"" + item.EvalType + "\"  attribute=\"" + item.Attribute + "\" status=\"" + item.Status + "\">&nbsp;&nbsp;&nbsp;&nbsp;" + item.Caption + "</a></li>";
                    index++;
                }
            }
            str += "<li id=\"detailLi\" style=\"display: none;\"><a href=\"#\">&nbsp;&nbsp;&nbsp;&nbsp;分数录入</a></li>";


            Response.Write("dd.innerHTML = '';");
            Response.Write("dd.innerHTML = '" + str + "';");
 
            Response.Write("}");

            IStuCauseEvalHistoryLogic logic = Container<IStuCauseEvalHistoryLogic>.Instance;
            SchoolInfo si = SchoolCommon.Sch_SchoolInfo;
            int schoolYear = si.SchoolYear;
            int term = si.SchoolTerm;
            string schoolMark = si.SchoolMark;

            Hashtable ht = new Hashtable();
            ht.Add("SchoolYear", schoolYear);
            ht.Add("Term", term);
            ht.Add("SchoolMark", schoolMark);
            IList<StuCauseEvalHistory> schList = logic.FindAll(ht);
            if (SchoolCommon.CheckRole((int)RoleKeyEnum.Class_Teacher))
            {
                Response.Write("parent.frames[\"mainFrame\"].location.href = \"Overview.aspx?id=" + firestId + "&evaltype=1&attribute=3\"");
                //Response.Write("document.getElementById('" + firestId + "').click();");
                return;
            }
            foreach (StuCauseEvalHistory history in schList)
            {

                if (history.Status > 0 && history.RID == firestId)
                {
                    if (SchoolCommon.CheckRole((int)RoleKeyEnum.Teach_Director))
                        //Response.Write("parent.frames[\"mainFrame\"].location.href = \"TeacherOverview.aspx?id=" + firestId + "&evaltype=1&attribute=3\"");
                        Response.Write("var tobj = document.getElementById('" + firestId + "');if(tobj !=null)tobj.click();");
                    return;
                }
            }
            Response.Write("parent.frames[\"mainFrame\"].location.href = \"msgPage.html\"");
        }
    }

    /// <summary>
    /// 获取当前学年学期的带有课程名的学分记录
    /// </summary>
    /// <returns></returns>
    private IList<StuCasueHistoryView> GetEvalList()
    {
        IList<StuCasueHistoryView> mhvs = new List<StuCasueHistoryView>();
        SchoolInfo si = SchoolCommon.Sch_SchoolInfo;
        int schoolYear = si.SchoolYear;
        int term = si.SchoolTerm;

        ITeacherEvalHistoryLogic logic = Container<ITeacherEvalHistoryLogic>.Instance;


        Hashtable ht = new Hashtable();
        ht.Add("SchoolYear", schoolYear);
        ht.Add("Term", term);
        ht.Add("SchoolMark", si.SchoolMark);
        ht.Add("Site", StuCauseEvalHistory.SystemSiteName);
        IList<TeacherEvalHistory> list = logic.FindAll(ht);
        foreach (TeacherEvalHistory cl in list)
        {
            StuCasueHistoryView mhv = new StuCasueHistoryView();
            mhv.EvalType = 3;
            mhv.Attribute = cl.Attribute;
            mhv.Caption = cl.Caption;
            mhv.KeyWord = cl.KeyWord;
            mhv.ManagerID = cl.ManagerID;
            mhv.RID = cl.RID;
            mhv.SchoolMark = cl.SchoolMark;
            mhv.SchoolYear = cl.SchoolYear;
            mhv.Site = cl.Site;
            mhv.Status = cl.Status;
            mhv.Term = cl.Term;
            mhvs.Add(mhv);
        }

        IClassEvalHistoryLogic logic1 = Container<IClassEvalHistoryLogic>.Instance;

        ht = new Hashtable();
        ht.Add("SchoolYear", schoolYear);
        ht.Add("Term", term);
        ht.Add("SchoolMark", si.SchoolMark);
        ht.Add("Site", StuCauseEvalHistory.SystemSiteName);
        IList<ClassEvalHistory> list2 = logic1.FindAll(ht);

        foreach (ClassEvalHistory cl in list2)
        {
            StuCasueHistoryView mhv = new StuCasueHistoryView();
            mhv.EvalType = 2;
            mhv.Attribute = cl.Attribute;
            mhv.Caption = cl.Caption;
            mhv.KeyWord = cl.KeyWord;
            mhv.ManagerID = cl.ManagerID;
            mhv.RID = cl.RID;
            mhv.SchoolMark = cl.SchoolMark;
            mhv.SchoolYear = cl.SchoolYear;
            mhv.Site = cl.Site;
            mhv.Status = cl.Status;
            mhv.Term = cl.Term;
            mhvs.Add(mhv);
        }




        IMoralityHistoryLogic mlogic = Container<IMoralityHistoryLogic>.Instance;

        ht = new Hashtable();
        ht.Add("SchoolYear", schoolYear);
        ht.Add("Term", term);
        ht.Add("SchoolMark", si.SchoolMark);
        ht.Add("Site", MoralityHistory.SystemSiteName);
        IList<MoralityHistory> mlist = mlogic.FindAll(ht);
        foreach (MoralityHistory cl in mlist)
        {
            StuCasueHistoryView mhv = new StuCasueHistoryView();
            mhv.EvalType = 4;
            mhv.Attribute = cl.Attribute;
            mhv.Caption = cl.Caption;
            mhv.KeyWord = cl.KeyWord;
            mhv.ManagerID = cl.ManagerID;
            mhv.RID = cl.RID;
            mhv.SchoolMark = cl.SchoolMark;
            mhv.SchoolYear = cl.SchoolYear;
            mhv.Site = cl.Site;
            mhv.Status = cl.Status;
            mhv.Term = cl.Term;
            mhvs.Add(mhv);
        }

        return mhvs;
    }
}
